package com.fan.txl.mock.api.service.mock;
import android.app.Application;
import android.content.res.AssetManager;

import com.fan.txl.TxlApplication;
import com.fan.txl.TxlApplicationLike;
import com.fan.txl.mock.api.annotation.MockRspData;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.List;

import okhttp3.Response;

/**
 * Created by jiajiabao on 17-1-16.
 */

public class Service {

    @Deprecated
    public String readMockRsp(MockRspData mockRspData){
        StringBuilder rsp = new StringBuilder();
        if (!mockRspData.isMock()){
            return rsp.toString();
        }
        try {
            InputStream is = TxlApplicationLike.getApp().getAssets().open(mockRspData.getPath());
            BufferedReader r = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = r.readLine()) != null) {
                rsp.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return rsp.toString();
    }


    public String readMockRsp(String service, String method){
        //mock/oauth2/auth.json
        String path="mock/"+service+"/"+method+".json";
        StringBuilder rsp = new StringBuilder();
        try {
            InputStream is = TxlApplicationLike.getApp().getAssets().open(path);
            BufferedReader r = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = r.readLine()) != null) {
                rsp.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return rsp.toString();
    }

}
